package com.dxiang.demo.web.controller;

import com.dxiang.demo.model.GameInfo;
import com.dxiang.demo.service.GameClassificationService;
import com.dxiang.demo.service.GameInfoService;
import com.dxiang.demo.utils.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * @author Jerry
 */
@RestController
public class GameInfoController extends BaseController
{
	private final Logger log = LoggerFactory.getLogger(GameInfoController.class);

    @Autowired
    private GameInfoService gameInfoService;

    @Autowired
    private GameClassificationService classificationService;




    /**
     * 帖子详情
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping("/getGameInfo")
    public ResponseEntity<?> getGameInfo() throws Exception
    {
    	return success(gameInfoService.getGameInfo());
    }
    
    @PostMapping("/saveGameInfo")
    public ResponseEntity<?> saveGameInfo(@Valid @RequestBody GameInfo  gameInfo) throws Exception
    {
//    	log.info("接收参数："+gameinfo);
//    	JSONObject json=JSONObject.parseObject(gameinfo);
//    	GameInfo gameInfo = JSONObject.toJavaObject(json, GameInfo.class);
    	//GameInfo gameInfo = new GameInfo();
    	//gameInfo.setGameTags(gameinfo);
    	//GameInfoDto dto = null;
    	//GameInfo gameInfo = BeanMapDozer.map(dto, GameInfo.class);
    	return success(gameInfoService.insert(gameInfo));
    }

    @RequestMapping("/game/recommend")
    public  ResponseEntity<?> getRecommend() throws Exception{
        return success(gameInfoService.getRecommend());
    }

    @PostMapping("/game/details")
    public ResponseEntity<?> getGameDetails(String id) throws Exception{
        return success(gameInfoService.getGameDetails(id));
    }


    @RequestMapping("/game/classification")
    public ResponseEntity<?> getGameClassification() throws  Exception{
        return success(classificationService.getGameClassification());
    }


    @RequestMapping("/game/newlist")
    public ResponseEntity<?> getNewList() throws Exception{
        return success(gameInfoService.getNewList());
    }


    @RequestMapping("/game/nearByUpdate")
    public ResponseEntity<?> getNearByUpdate() throws Exception{
        return success(gameInfoService.getNearUpdateList());
    }



    /**
     * #####################################################################  PC 端接口 #################################################################
     * @return
     * @throws Exception
     */



    @RequestMapping("/pc/pchome")
    public ResponseEntity<?> getPCHome() throws Exception{
        return success(gameInfoService.getPCHomePageGameInfo());
    }

    @RequestMapping("/pc/crackPage")
    public ResponseEntity<?> getGameInfoByClfyAndUpdate() throws  Exception{
        return success(gameInfoService.getPCCrackPage("1",null));
    }

    @RequestMapping("/pc/searchPage")
    public ResponseEntity<?> searchGame() throws Exception{
        return success(gameInfoService.searchPage());
    }

    @RequestMapping("/pc/upPage")
    public <T> ResponseEntity<?> getUpRecommendList(ResultCode rstCode) throws Exception{
        return success(gameInfoService.getUpRecommand());
    }

    @PostMapping("/pc/search")
    public ResponseEntity<?> searchGame(String keyWord) throws Exception{
        return success(gameInfoService.searchGames(keyWord));
    }



    /**
     * #####################################################################  H5 端接口 #################################################################
     * @return
     * @throws Exception
     */
    /**
     * H5 首页
     */
    @RequestMapping("/h5/homePage")
    public ResponseEntity<?> homePage() throws Exception{
        return success(gameInfoService.h5Home());
    }

}
